<?php

function _q() {
	return \Library\Db\QueryProvider::getProvider();
}

function _u( \Bean\User $user = null ) {
	if( $user ) {
		return $user;
	}
	return \Library\Auth\Session::getSession()->getUser();
}

function _d() {
	return \Library\Database::getDb();
}

// Assertion
function _a( $t, $m = 'Assertion failed' ) {
	if( !$t ) {
		throw new \Exception( $m );
	}
}

// Check & exception
function _c( $checker, $data ) {
	$class = '\Library\Checker\\' . $checker . 'Checker';
	$result = $class::check( $data );
	if( $result !== true ) {
		throw new \Exception( $result );
	}
}

function _s( $txt ) {
	return htmlentities( $txt, ENT_COMPAT, 'UTF-8' );
}

function _view( $name, \Library\View $context ) {
	return new \Library\View\VirtualView( $name, $context );
}

function _now() {
	return date( 'Y-m-d H:i:s' );
}
